package chapter5;

import java.util.*;

public class ArraysDemo {
	public static void main(String[] args) {

		// 用Array.sort()对数组arr的元素进行升序排序
		int[] arr = { 56, -70, 7, 452, 85, 0 };
		Arrays.sort(arr);
		System.out.println(Arrays.toString(arr));

		// 用Arrays.equals()比较arr1和arr2两个数组是否相等
		int[] arr1 = { 56, -70, 7, 452, 85, 0 };
		int[] arr2 = { 56, -70, 7, 452, 85, 0 };
		int[] arr3 = { 56, -70, 93, 452, 85, 0 };
		int[] arr4 = { 56, -70, 7, 452, 0 };
		int[] arr5 = { 56, 7, -70, 452, 85, 0 };
		System.out.println("\n" + Arrays.equals(arr1, arr2));
		System.out.println(Arrays.equals(arr1, arr3));
		System.out.println(Arrays.equals(arr1, arr4));
		System.out.println(Arrays.equals(arr1, arr5) + "\n");

		// 用Arrays.toString()将数组arr22转换成一个字符串
		int[] arr22 = { 56, -70, 7, 452, 85, 0 };
		System.out.println(Arrays.toString(arr22) + "\n");

		// 用Arrays.fill()把数组arr所有元素都赋值为val
		int[] arrs = { 56, -70, 7, 452, 85, 0 };
		Arrays.fill(arrs, 35);
		System.out.println(Arrays.toString(arrs) + "\n");

		// 用Arrays.copyof() 把数组arrs1复制成一个长度为length的新数组
		int[] arrs1 = { 56, -70, 7, 452, 85, 0 };
		int[] arrs2 = Arrays.copyOf(arrs1, 4);
		int[] arrs3 = Arrays.copyOf(arrs1, 9);
		System.out.println(Arrays.toString(arrs2));
		System.out.println(Arrays.toString(arrs3) + "\n");

		// 用Arrays.binarySearch()查询元素值var在数字array中的下标
		int[] arr11 = { 56, -70, 7, 452, 85, 0 };
		int index1 = Arrays.binarySearch(arr11, 7);
		int index2 = Arrays.binarySearch(arr11, 3);
		System.out.println(index1);
		System.out.println(index2);
	}
}
